package cn.donting.jme.edit.ui.inspector.imp.mesh;

import cn.donting.jme.edit.attribute.Attribute;
import cn.donting.jme.edit.ex.AttributeLoader;
import cn.donting.jme.edit.ex.ExResourcesLoad;
import cn.donting.jme.edit.ex.InspectorUILoader;
import cn.donting.jme.edit.ui.inspector.AttributeInspectorUI;
import cn.donting.jme.edit.ui.inspector.InspectorUI;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Spatial;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Mesh 检查视图
 */
public class MeshInspectorUILoader implements InspectorUILoader {


    @Override
    public List<InspectorUI> getInspectorUI(Spatial spatial) throws IOException {

        List<InspectorUI> inspectorUIS = new ArrayList<>();
        if (!(spatial instanceof Geometry)) return inspectorUIS;
        Geometry geometry = (Geometry) spatial;
        Mesh mesh = geometry.getMesh();

        AttributeInspectorUI attributeInspectorUI = new AttributeInspectorUI("网格", null);
        inspectorUIS.add(attributeInspectorUI);
        List<AttributeLoader> attributeLoaders = ExResourcesLoad.getAttributeLoaders(mesh);
        for (AttributeLoader attributeLoader : attributeLoaders) {
            List<Attribute> attributes = attributeLoader.getAttribute(mesh);
            attributeInspectorUI.addAttribute(attributes);
        }
        return inspectorUIS;
    }
}
